<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs v-model="activeName" @tab-click="tabClick">
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:">
                <el-input v-model="formData.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button @click="saveUserDetail" type="primary">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <UserInfo />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <JobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetail, saveUserDetail} from '@/api/user'
import Cookie from 'js-cookie'
import UserInfo from './components/UserInfo.vue'
import JobInfo from './components/JobInfo.vue'
export default {
    data() {
        return {
            formData: {},
            activeName: Cookie.get('activeName') || '0'
        }
    },
    components: {
        UserInfo,
        JobInfo
    },
    created() {
        this.getUnserInfo()
    },
    methods: {
        async getUnserInfo() {
            const res = await getUserDetail(this.$route.params.id)
            this.formData = { ...res, password: ''}
        },
        async saveUserDetail() {
           await saveUserDetail(this.formData)
           this.$message.success('更新成功')
        },
        tabClick() {
            Cookie.set('activeName', this.activeName)
        }
    }
}
</script>

<style>

</style>